package com.bridgetree.jubaocrm.ui.project;

import java.util.HashMap;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bridgetree.jubaocrm.R;

/**
 * 项目更改营销状态设配器
 * 
 * @author Administrator
 * 
 */
public class XMEditMarkingAdapter extends BaseAdapter {
	private String[] Date = null;
	private int index = 0;
	private Context context;
	private LayoutInflater mInflater;
	public HashMap<Integer, Bitmap> cachedBitmap;

	private class GridHolder {
		ImageView line;
		ImageView imageView1;
		TextView name;
	}

	@SuppressLint("UseSparseArrays")
	public XMEditMarkingAdapter(Context c, String[] mins, int index) {
		super();
		this.context = c;
		this.index = index;
		this.Date = mins;
		mInflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public int getCount() {
		return Date.length;
	}

	@Override
	public Object getItem(int index) {
		return Date[index];
	}

	@Override
	public long getItemId(int index) {
		return index;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		final GridHolder holder;
		if (convertView == null) {
			convertView = mInflater
					.inflate(R.layout.xm_edit_marjing_item, null);
			holder = new GridHolder();
			holder.line = (ImageView) convertView.findViewById(R.id.line);
			holder.imageView1 = (ImageView) convertView
					.findViewById(R.id.imageView1);
			holder.name = (TextView) convertView.findViewById(R.id.name);
			convertView.setTag(holder);
		} else {
			holder = (GridHolder) convertView.getTag();
		}

		final String xm_txt = Date[position];
		holder.name.setText(xm_txt);
		if (position == index) {
			holder.imageView1.setVisibility(View.VISIBLE);
		} else {
			holder.imageView1.setVisibility(View.INVISIBLE);
		}
		holder.name.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				XMChildActivity.index =position;
				index =position;
				for(int i =0;i<Date.length;i++){
					holder.imageView1.setVisibility(View.INVISIBLE);
				}
				if (position == index) {
					holder.imageView1.setVisibility(View.VISIBLE);
				} else {
					holder.imageView1.setVisibility(View.INVISIBLE);
				}
				notifyDataSetChanged();
			}
		});
		
//		if (position == Date.length - 1) {
//			holder.line.setVisibility(View.INVISIBLE);
//		}
		return convertView;
	}
}
